import com.google.inject.AbstractModule;

import de.mlp_distributed.mlp.core.MultiLayerPerceptron;
import de.mlp_distributed.mlp.math.Factory;
import de.mlp_distributed.mlp.math.JBlasMatrixFactory;
import de.mlp_distributed.mlp.math.JBlasVectorFactory;
import de.mlp_distributed.mlp.math.MatrixFactory;
import de.mlp_distributed.mlp.math.VectorFactory;
import de.mlp_distributed.mlp.math.mahout.Vector;

public class TestMLP {
	private static final int SIZE = 500;

	public static void main(final String[] args) throws Exception {

		class FactoryModule extends AbstractModule {

			@Override
			protected void configure() {
				this.bind(VectorFactory.class).to(JBlasVectorFactory.class);
				this.bind(MatrixFactory.class).to(JBlasMatrixFactory.class);
				// this.bind(VectorFactory.class).to(MahoutVectorFactory.class);
				// this.bind(MatrixFactory.class).to(MahoutMatrixFactory.class);
			}

		}
		final Factory f = Factory.getInstance(new FactoryModule());

		final MultiLayerPerceptron mlp = new MultiLayerPerceptron(TestMLP.SIZE, TestMLP.SIZE, new int[] { TestMLP.SIZE }, false);

		final Vector input = f.getVectorFactory().construct(TestMLP.SIZE);
		final Vector target = f.getVectorFactory().construct(TestMLP.SIZE);

		TestMLP.fillVector(input, 0);
		TestMLP.fillVector(target, 0);

		input.set(1, 1);
		target.set(2, 1);
		long startTime = 0;
		for (int i = 0; i < 100; i++) {
			startTime = System.currentTimeMillis();
			mlp.trainOnline(input, target);
			System.out.println("train " + ((System.currentTimeMillis() - startTime)) + " ms");
		}

	}

	static void fillVector(final Vector v, final int value) {
		for (int i = 0; i < v.size(); i++) {
			v.set(i, value);
		}
	}
}
